﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public enum EnemyStateID
{
    NullStateID,
    Chase,
    Attack
}
public enum EnemyTransition
{
    NullTransition,
    CanAttack,
    LostSoldier
}
public abstract class IEnemyState  {
    protected Dictionary<EnemyTransition, EnemyStateID> map = new Dictionary<EnemyTransition, EnemyStateID>(); 
    protected EnemyStateID currentStateID;
    protected EnemyFSMSystem m_fsm;
    protected Character m_character;
    public EnemyStateID GetStateID
    {
        get { return currentStateID; }
    }

    public IEnemyState (EnemyFSMSystem fsm,Character character)
    {
        m_fsm = fsm;
        m_character = character;
    }
    public void AddTransition(EnemyTransition transiton, EnemyStateID stateID)
    {
        //安全校验
        if (transiton == EnemyTransition.NullTransition) Debug.LogError("NullTransiton");
        if (stateID == EnemyStateID.NullStateID) Debug.LogError("NullStateID");
        if (map.ContainsKey(transiton)) Debug.LogError("Contains " + transiton.ToString());
        //实现
        map.Add(transiton, stateID);
    }
    //从字典中删除
    public void DeleteTransition(EnemyTransition transiton)
    {
        //安全校验
        if (transiton == EnemyTransition.NullTransition) Debug.LogError("NullTranstion");
        if (!map.ContainsKey(transiton)) Debug.LogError("dosen't exit " + transiton.ToString());
        //实现
        map.Remove(transiton);
    }

    /// <summary>
    /// 在转换状态中获得下一个状态
    /// </summary>
    /// <param name="transition"></param>
    /// <returns></returns>
    public EnemyStateID GetStateIDFromTransition(EnemyTransition transition)
    {
        return EnemyStateID.NullStateID;
    }

    /// <summary>
    /// 进入该状态的时候的动作
    /// </summary>
    public virtual void DoBeforeEntering() { }
    /// <summary>
    /// 离开该状态时候的动作
    /// </summary>
    public virtual void DoBeforeLeaving() { }
    /// <summary>
    /// 该状态需要做的 每帧调用
    /// </summary>
    public abstract void Act(List<Character> targets);
    /// <summary>
    /// 该状态切换到另一个状态的条件判断
    /// </summary>
    public abstract void Reason(List<Character> targets);
}
